package observepattern;

import java.util.ArrayList;
import java.util.List;

/**
 * 观察者模式 -- 被观察者 meeting 开会
 * Meeting.java
 * @author yaojinshan
 * @since 2017年6月19日 下午1:41:38
 *
 */
public class Meeting {
	private List<MeetingObserver> meetingPersonList = new ArrayList<>();
	public void attach(MeetingObserver mo){
			if(!meetingPersonList.contains(mo)){
				meetingPersonList.add(mo);
			};
	}
	public List<MeetingObserver> getMeetingPersonList() {
		return meetingPersonList;
	}
	public void setMeetingPersonList(List<MeetingObserver> meetingPersonList) {
		this.meetingPersonList = meetingPersonList;
	}
	public void addMeeting(){
		System.out.println("发起一个会议,并通知所有人！");
		notifyAllMeetingObserver();
	}
	//通知所有会议观察者成员
	private void notifyAllMeetingObserver() {
		for(MeetingObserver mo :meetingPersonList){
			mo.notifyPersonToMeeting();
		}
	}
}
